home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / dflat8.zip / BUTTON.C < prev    next >
Text File  |  1991-09-30  |  6KB  |  259 lines

  1. /* -------------- button.c -------------- */
  2.  
  3. #include "dflat.h"
  4.  
  5. int ButtonProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
  6. {
  7.     CTLWINDOW *ct = GetControl(wnd);
  8.     int x;
  9.     if (ct != NULL)    {
  10.         switch (msg)    {
  11.             case SETFOCUS:
  12.                 BaseWndProc(BUTTON, wnd, msg, p1, p2);
  13.                 /* ------- fall through ------- */
  14.             case PAINT:
  15.                 if (isVisible(wnd))    {
  16.                     if (TestAttribute(wnd, SHADOW))    {
  17.                         /* -------- draw the button's shadow ------- */
  18.                         background = WndBackground(GetParent(wnd));
  19.                         foreground = BLACK;
  20.                         for (x = 1; x <= WindowWidth(wnd); x++)
  21.                             wputch(wnd, 223, x, 1);
  22.                         wputch(wnd, 220, WindowWidth(wnd), 0);
  23.                     }
  24.                     if (ct->itext != NULL)    {
  25.                         unsigned char *txt;
  26.                         if ((txt = calloc(1, strlen(ct->itext)+10)) != NULL)    {
  27.                             if (ct->setting == OFF)    {
  28.                                 txt[0] = CHANGECOLOR;
  29.                                 txt[1] = wnd->WindowColors [HILITE_COLOR] [FG] | 0x80;
  30.                                 txt[2] = wnd->WindowColors [STD_COLOR] [BG] | 0x80;
  31.                             }
  32.                             CopyCommand(txt+strlen(txt), ct->itext, !ct->setting,
  33.                                 WndBackground(wnd));
  34.                             SendMessage(wnd, CLEARTEXT, 0, 0);
  35.                             SendMessage(wnd, ADDTEXT, (PARAM) txt, 0);
  36.                             free(txt);
  37.                         }
  38.                     }
  39.                     /* --------- write the button's text ------- */
  40.                     WriteTextLine(wnd, NULL, 0, wnd == inFocus);
  41.                 }
  42.                 return TRUE;
  43.             case KEYBOARD:
  44.                 if (p1 != '\r')
  45.                     break;
  46.                 /* ---- fall through ---- */
  47.             case LEFT_BUTTON:
  48.                 /* --------- draw a pushed button -------- */
  49.                 background = WndBackground(GetParent(wnd));
  50.                 foreground = WndBackground(wnd);
  51.                 wputch(wnd, ' ', 0, 0);
  52.                 for (x = 0; x < WindowWidth(wnd); x++)    {
  53.                     wputch(wnd, 220, x+1, 0);
  54.                     wputch(wnd, 223, x+1, 1);
  55.                 }
  56.                 if (msg == LEFT_BUTTON)
  57.                     SendMessage(NULL, WAITMOUSE, 0, 0);
  58.                 else
  59.                     SendMessage(NULL, WAITKEYBOARD, 0, 0);
  60.                 SendMessage(wnd, PAINT, 0, 0);
  61.                 if (ct->setting == ON)
  62.                     PostMessage(GetParent(wnd), COMMAND, ct->command, 0);
  63.                 else
  64.                     beep();
  65.                 return TRUE;
  66.             case HORIZSCROLL:
  67.                 return TRUE;
  68.             default:
  69.                 break;
  70.         }
  71.     }
  72.     return BaseWndProc(BUTTON, wnd, msg, p1, p2);
  73. }
  74.  
  75. int TextProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
  76. {
  77.     CTLWINDOW *ct;
  78.     int rtn;
  79.     switch (msg)    {
  80.         case CREATE_WINDOW:
  81.             rtn = BaseWndProc(TEXT, wnd, msg, p1, p2);
  82.             ct = GetControl(wnd);
  83.             if (ct != NULL && ct->itext != NULL)    {
  84.                 char *cp = ct->itext;
  85.                 int len = min(ct->dwnd.h, MsgHeight(cp));
  86.                 int i;
  87.                 for (i = 0; i < len; i++)    {
  88.                     int mlen;
  89.                     char *txt = cp;
  90.                     char *cp1 = cp;
  91.                     char *np = strchr(cp, '\n');
  92.                     if (np != NULL)
  93.                         *np = '\0';
  94.                     mlen = strlen(cp);
  95.                     while ((cp1 = strchr(cp1, SHORTCUTCHAR)) != NULL)    {
  96.                         mlen += 3;
  97.                         cp1++;
  98.                     }
  99.                     if (np != NULL)
  100.                         *np = '\n';
  101.                     if ((txt = malloc(mlen+1)) != NULL)    {
  102.                          CopyCommand(txt, cp, FALSE, WndBackground(wnd));
  103.                         txt[mlen] = '\0';
  104.                         SendMessage(wnd, ADDTEXT, (PARAM)txt, 0);
  105.                         if ((cp = strchr(cp, '\n')) != NULL)
  106.                             cp++;
  107.                         free(txt);
  108.                     }
  109.                 }
  110.             }
  111.             return rtn;
  112.         default:
  113.             break;
  114.     }
  115.     return BaseWndProc(TEXT, wnd, msg, p1, p2);
  116. }
  117.  
  118. static void SetFocusCursor(WINDOW wnd)
  119. {
  120.     if (wnd == inFocus)    {
  121.         SendMessage(NULL, SHOW_CURSOR, 0, 0);
  122.         SendMessage(wnd, KEYBOARD_CURSOR, 1, 0);
  123.     }
  124.     else
  125.         SendMessage(NULL, HIDE_CURSOR, 0, 0);
  126. }
  127.  
  128. int RadioButtonProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
  129. {
  130.     int rtn;
  131.     DBOX *db = GetParent(wnd)->extension;
  132.     CTLWINDOW *ct = GetControl(wnd);
  133.     if (ct != NULL)    {
  134.         switch (msg)    {
  135.             case SETFOCUS:
  136.             case MOVE:
  137.                 rtn = BaseWndProc(RADIOBUTTON, wnd, msg, p1, p2);
  138.                 SetFocusCursor(wnd);
  139.                 return rtn;
  140.             case PAINT:    {
  141.                 char rb[] = "( )";
  142.                 if (ct->setting)
  143.                     rb[1] = 7;
  144.                 SendMessage(wnd, CLEARTEXT, 0, 0);
  145.                 SendMessage(wnd, ADDTEXT, (PARAM) rb, 0);
  146.                 break;
  147.             }
  148.             case KEYBOARD:
  149.                 if ((int)p1 != ' ')
  150.                     break;
  151.             case LEFT_BUTTON:
  152.                 PushRadioButton(db, ct->command);
  153.                 break;
  154.             default:
  155.                 break;
  156.         }
  157.     }
  158.     return BaseWndProc(RADIOBUTTON, wnd, msg, p1, p2);
  159. }
  160.  
  161. int CheckBoxProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
  162. {
  163.     int rtn;
  164.     CTLWINDOW *ct = GetControl(wnd);
  165.     if (ct != NULL)    {
  166.         switch (msg)    {
  167.             case SETFOCUS:
  168.             case MOVE:
  169.                 rtn = BaseWndProc(CHECKBOX, wnd, msg, p1, p2);
  170.                 SetFocusCursor(wnd);
  171.                 return rtn;
  172.             case PAINT:    {
  173.                 char cb[] = "[ ]";
  174.                 if (ct->setting)
  175.                     cb[1] = 'X';
  176.                 SendMessage(wnd, CLEARTEXT, 0, 0);
  177.                 SendMessage(wnd, ADDTEXT, (PARAM) cb, 0);
  178.                 break;
  179.             }
  180.             case KEYBOARD:
  181.                 if ((int)p1 != ' ')
  182.                     break;
  183.             case LEFT_BUTTON:
  184.                 ct->setting ^= ON;
  185.                 SendMessage(wnd, PAINT, 0, 0);
  186.                 break;
  187.             default:
  188.                 break;
  189.         }
  190.     }
  191.     return BaseWndProc(CHECKBOX, wnd, msg, p1, p2);
  192. }
  193.  
  194. int BoxProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
  195. {
  196.     int rtn;
  197.     CTLWINDOW *ct = GetControl(wnd);
  198.     if (ct != NULL)    {
  199.         switch (msg)    {
  200.             case SETFOCUS:
  201.             case PAINT:
  202.                 return FALSE;
  203.             case LEFT_BUTTON:
  204.             case BUTTON_RELEASED:
  205.                 return SendMessage(GetParent(wnd), msg, p1, p2);
  206.             case BORDER:
  207.                 rtn = BaseWndProc(BOX, wnd, msg, p1, p2);
  208.                 if (ct != NULL)
  209.                     if (ct->itext != NULL)
  210.                         writeline(wnd, ct->itext, 1, 0, FALSE);
  211.                 return rtn;
  212.             default:
  213.                 break;
  214.         }
  215.     }
  216.     return BaseWndProc(BOX, wnd, msg, p1, p2);
  217. }
  218.  
  219. int SpinButtonProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
  220. {
  221.     int rtn;
  222.     CTLWINDOW *ct = GetControl(wnd);
  223.     if (ct != NULL)    {
  224.         switch (msg)    {
  225.             case CREATE_WINDOW:
  226.                 wnd->wd -= 2;
  227.                 wnd->rc.rt -= 2;
  228.                 break;
  229.             case SETFOCUS:
  230.                 rtn = BaseWndProc(SPINBUTTON, wnd, msg, p1, p2);
  231.                 SetFocusCursor(wnd);
  232.                 return rtn;
  233.             case PAINT:
  234.                 foreground = FrameForeground(wnd);
  235.                 background = FrameBackground(wnd);
  236.                 wputch(wnd, UPSCROLLBOX, WindowWidth(wnd), 0);
  237.                 wputch(wnd, DOWNSCROLLBOX, WindowWidth(wnd)+1, 0);
  238.                 break;
  239.             case LEFT_BUTTON:
  240.                 if (p1 == GetRight(wnd) + 1)
  241.                     SendMessage(wnd, KEYBOARD, UP, 0);
  242.                 else if (p1 == GetRight(wnd) + 2)
  243.                     SendMessage(wnd, KEYBOARD, DN, 0);
  244.                 if (wnd != inFocus)
  245.                     SendMessage(wnd, SETFOCUS, TRUE, 0);
  246.                 return TRUE;
  247.             case LB_SETSELECTION:
  248.                 rtn = BaseWndProc(SPINBUTTON, wnd, msg, p1, p2);
  249.                 wnd->wtop = (int) p1;
  250.                 SendMessage(wnd, PAINT, 0, 0);
  251.                 return rtn;
  252.             default:
  253.                 break;
  254.         }
  255.     }
  256.     return BaseWndProc(SPINBUTTON, wnd, msg, p1, p2);
  257. }
  258.  
  259.